package piece1.chapter5;

public class Problem5_23 {

    /**
     * @param args
     */
    public static void main(String[] args) {
	// TODO 自动生成的方法存根
	int[][] a = { { 1, 2 }, { 4, 3 } };
	int[][] b = { { 1, 1 }, { 1, 1 } };
	int[][] c = multiplyMatrix(a, b);
	for (int i = 0; i < c.length; i++) {
	    for (int j = 0; j < c[0].length; j++) {
		System.out.println(c[i][j]);
	    }
	}

    }

    public static int[][] multiplyMatrix(int[][] a, int[][] b) {
	if (a.length == b[0].length) {
	    int[][] result = new int[a.length][b[1].length];
	    for (int i = 0; i < result.length; i++) {
		for (int j = 0; j < result[0].length; j++) {

		    for (int k = 0; k < result.length; k++) {
			result[i][j] += a[i][k] * b[k][j];
		    }

		}
	    }
	    return result;
	}

	else {
	    System.out.println("输入矩阵有误,前一矩阵的列数必须与后一矩阵的行数相同");
	}
	return b;

    }
}
